<?php

namespace App\Module\User\Request\Foot;

use App\Constants\Constant;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Validation\Request\FormRequest;
use Hyperf\Validation\Rule;
use Qbhy\HyperfAuth\AuthManager;

class CreateRequest extends FormRequest{

    /**
     * @Inject()
     * @var AuthManager $authManager
     */
    private $authManager;

    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'child_id'=>['required',Rule::exists("child","child_id")->whereIn("child_id",$this->authManager->guard(Constant::USER)->user()->childs()->pluck("child.child_id")->toArray())],
            'is_public'=>['required',Rule::in([Constant::FOOT_PRIVATE,Constant::FOOT_PUBLIC])],
            'content'=>'required_without:resources',
            'resources'=>'required_without:content|array',
            'resources.*'=>'url',
            'resource_type'=>['required_with:resources',Rule::in([Constant::RESOURCE_TYPE_PICTURE,Constant::RESOURCE_TYPE_VIDEO])]
        ];
    }
}